#! /bin/bash
if [[ `whoami` != "root" ]] ; then
	echo "This Script must be run as ROOT."
	exit
fi
PWD="$( cd "$( dirname "$0" )" && pwd )"
MOUNT="$PWD/rootDir/"
START_PARTITION=16384 #Put here byte size of partition start.
#This size is sector beginning of partition * sector size
SIZE_PARTITION=-1 #Put here size of the partition
#Use -1 if the partition is on the entire disk file.
DISKFILE="$PWD/geanOS.img" # Name of the disk file.

LOOP_DEV=`losetup -f`
if [[ $SIZE_PARTITION == -1 ]] ; then
	losetup -o $START_PARTITION $LOOP_DEV $DISKFILE
	mount -t ext2 $LOOP_DEV $MOUNT
	echo "Partition mounted on $MOUNT"
	touch $PWD/`basename $LOOP_DEV`
else
	losetup -o $START_PARTITION --sizelimit $SIZE_PARTITION $LOOP_DEV $DISKFILE
	mount -t ext2 $LOOP_DEV $MOUNT
	echo "Partition mounted on $MOUNT"
	touch $PWD/`basename $LOOP_DEV`
fi
